﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace devtm.Aop.InternalProcess.Cache
{

    public class CacheTimer
    {

        #region Ctor

        public CacheTimer()
        {

        }

        public CacheTimer(TimeSpan span, bool sliding)
        {
            this.Interval = span;
            this.Sliding = sliding;
            this.Reset();
        }

        #endregion

        public void Reset() { NextExpiration = DateTime.Now.Add(Interval); }

        public DateTime NextExpiration { get; set; }
        public TimeSpan Interval { get; set; }
        public bool Sliding { get; set; }

        public bool Expired { get { return NextExpiration < DateTime.Now; } }



        /// <summary>
        /// Gets the time span for second
        /// </summary>
        /// <param name="second">The second.</param>
        /// <returns></returns>
        public static TimeSpan GetTimeSpan(int second)
        {

            //int hour = 0;
            //int minute = 0;
            //int day = 0;
            //ComputeTimeSpan(ref second, ref hour, ref minute, ref day);
            //var interval = new TimeSpan(day, hour, minute, second);


            var interval = new TimeSpan(0, 0, 0, second);

            return interval;

        }

        private static void ComputeTimeSpan(ref int seconde, ref int hour, ref int minute, ref int day)
        {
            if (seconde > dayCont)
            {
                day = (seconde / dayCont);
                seconde = seconde % dayCont;
            }
            if (seconde > HourCont)
            {
                hour = (seconde / HourCont);
                seconde = seconde % HourCont;
            }

            if (seconde > MinuteCont)
            {
                minute = (seconde / MinuteCont);
                seconde = seconde % MinuteCont;
            }
        }


        private const int MinuteCont = 60;
        private const int HourCont = 3600;
        private const int dayCont = 86400;



    }

    

}
